/// \file A3200SFPlayback.h
/// \brief Contains functions to configure Sensor Fusion data playback and initiate a data playback session.
///
/// Copyright (c) Aerotech, Inc. 2011-2015.
///

#include "A3200SFPlaybackInfo.h"
#include "A3200CommonTypes.h"
#include "A3200CommonStructures.h"

#ifndef __A3200_SFPLAYBACK__
#define __A3200_SFPLAYBACK__

#ifdef __cplusplus
extern "C" {
#endif

/// \defgroup sensorfusiondataplayback Sensor Fusion Data Playback Functions
/// @{

/// \brief The handle to the Sensor Fusion data playback Configuration.
///
/// This is used to hold the Sensor Fusion data playback Configuration.
typedef void* SFPlaybackHandle;

/// \brief The data playback status struct.
///
/// This struct will be filled in when checking the status of a currently executing data playback session.
typedef struct tagSFPlaybackStatus {
	DWORD updatesPlayed; ///< The number of updates played during the data playback session
	DATAPLAYBACKFLAGS statusFlags; ///< The status flags, as defined in A3200CommonStructures.h
	DWORD spare[4]; ///< Reserved for future expansion
} SFPlaybackStatus;

/// \brief Creates a new Sensor Fusion data playback configuration.
///
/// This function creates a new Sensor Fusion data playback configuration object. This object can then be used to configure data playback (specifying signals to output, start and output triggers, etc.). It is important to call A3200SFPlaybackFreeConfig() when one is finished using the handle, or else memory leaks will occur.
/// \param[out] pPlaybackHandle A pointer to a handle for the Sensor Fusion data playback configuration object
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackCreateConfig(SFPlaybackHandle* pPlaybackHandle);

/// \brief Frees a Sensor Fusion data playback configuration object.
///
/// This function cleans up a Sensor Fusion data playback configuration object that was created by A3200SFPlaybackCreateConfig(). Calling this function is necessary in order to clean up resources (memory) used by the configuration object.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackFreeConfig(SFPlaybackHandle playbackHandle);


/// \brief Configures the initial trigger to be triggered immediately.
///
/// This function configures the start trigger to be triggered immediately after a data playback session begins.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStartTriggerImmediately(SFPlaybackHandle playbackHandle);

/// \brief Configures the start trigger to be triggered on a digital input edge.
///
/// This function configures the start trigger to be triggered on a digital input rising and/or falling edge.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card number where the digital input is located
/// \param[in] bitNumber The bit number of the digital input
/// \param[in] edgeKind The kind of edge activity that triggers the start condition
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStartOnDigitalInput(SFPlaybackHandle playbackHandle, DWORD cardIndex, DWORD bitNumber, EDGE edgeKind);

/// \brief Configures the start trigger to be triggered on a digital output edge.
///
/// This function configures the start trigger to be triggered on a digital output rising and/or falling edge.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card number where the digital output is located
/// \param[in] bitNumber The bit number of the digital output
/// \param[in] edgeKind The kind of edge activity that triggers the start condition
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStartOnDigitalOutput(SFPlaybackHandle playbackHandle, DWORD cardIndex, DWORD bitNumber, EDGE edgeKind);

/// \brief Configures the start trigger to be triggered on a PSO event.
///
/// This function configures the start trigger to be triggered on a PSO event.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card index where the PSO card is located
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStartOnPSOEvent(SFPlaybackHandle playbackHandle, DWORD cardIndex);

/// \brief Configures the start trigger to be triggered on a PSO output event.
///
/// This function configures the start trigger to be triggered on a PSO output event.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card index where the PSO card is located
/// \param[in] outputNumber The PSO output number
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStartOnPSOOutput(SFPlaybackHandle playbackHandle, DWORD cardIndex, DWORD outputNumber);

/// \brief Configures the start trigger to be triggered on a PSO window event.
///
/// This function configures the start trigger to be triggered on a PSO window event.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card index where the PSO card is located
/// \param[in] windowNumber The PSO window number
/// \param[in] windowEventKind The kind of window activity that triggers the start condition
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStartOnPSOWindow(SFPlaybackHandle playbackHandle, DWORD cardIndex, DWORD windowNumber, WINDOWEVENT windowEventKind);

/// \brief Configures the time period that elapses between the output of a set of updates.
///
/// This function specifies the time period that elapses between the output of a set of updates.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] period The collection period
/// \param[in] timeUnit The units component of the specified collection period
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackOutputOnInterval(SFPlaybackHandle playbackHandle, DOUBLE period, TIMEUNIT timeUnit);

/// \brief Configures the output trigger to be triggered on a digital input edge.
///
/// This function configures the output trigger to be triggered on a digital input rising and/or falling edge.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card number where the digital input is located
/// \param[in] bitNumber The bit number of the digital input
/// \param[in] edgeKind The kind of edge activity that triggers the start condition
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackOutputOnDigitalInput(SFPlaybackHandle playbackHandle, DWORD cardIndex, DWORD bitNumber, EDGE edgeKind);

/// \brief Configures the output trigger to be triggered on a digital output edge.
///
/// This function configures the output trigger to be triggered on a digital output rising and/or falling edge.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card number where the digital output is located
/// \param[in] bitNumber The bit number of the digital output
/// \param[in] edgeKind The kind of edge activity that triggers the start condition
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackOutputOnDigitalOutput(SFPlaybackHandle playbackHandle, DWORD cardIndex, DWORD bitNumber, EDGE edgeKind);

/// \brief Configures the output trigger to be triggered on a PSO event.
///
/// This function configures the output trigger to be triggered on a PSO event.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card index where the PSO card is located
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackOutputOnPSOEvent(SFPlaybackHandle playbackHandle, DWORD cardIndex);

/// \brief Configures the output trigger to be triggered on a PSO output event.
///
/// This function configures the output trigger to be triggered on a PSO output event.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card index where the PSO card is located
/// \param[in] outputNumber The PSO output number
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackOutputOnPSOOutput(SFPlaybackHandle playbackHandle, DWORD cardIndex, DWORD outputNumber);

/// \brief Configures the output trigger to be triggered on a PSO window event.
///
/// This function configures the output trigger to be triggered on a PSO window event.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] cardIndex The Sensor Fusion card index where the PSO card is located
/// \param[in] windowNumber The PSO window number
/// \param[in] windowEventKind The kind of window activity that triggers the start condition
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackOutputOnPSOWindow(SFPlaybackHandle playbackHandle, DWORD cardIndex, DWORD windowNumber, WINDOWEVENT windowEventKind);

/// \brief Configure the playback session to output updates at the specified times.
///
/// This function configures the playback session to output updates at the specified times.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] times The output times
/// \param[in] timeCount The number of times in the specified array
/// \param[in] timeUnit The units component of the specified times
BOOL DLLENTRYDECLARATION A3200SFPlaybackOutputOnTimePoints(SFPlaybackHandle playbackHandle, DOUBLE* times, DWORD timeCount, TIMEUNIT timeUnit);

/// \brief Configures the playback output to repeat with the specified delay.
///
/// This function onfigures the playback output to repeat with the specified delay.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] delayTime The delay between playback cycles
/// \param[in] timeUnit The units component of the specified cycle delay time
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackRepeat(SFPlaybackHandle playbackHandle, DOUBLE delayTime, TIMEUNIT timeUnit);

/// \brief Adds a signal to be output during a data playback session.
///
/// This function specifies a Sensor Fusion data item to collect when playback is triggered.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] signal The kind of data signal to collect
/// \param[in] cardIndex The Sensor Fusion card number on which to output the data signal
/// \param[in] argument An optional argument that specifies additional data for the data signal to output. A value of 0 means that the argument value is ignored.
/// \param[in] data The values to be output
/// \param[in] dataCount The number of elements in the data array
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackAddSignal(SFPlaybackHandle playbackHandle, SFPLAYBACKSIGNAL signal, DWORD cardIndex, INT argument, DOUBLE* data, DWORD dataCount);

// \brief Configures the data playback session to consume the specified task.
///
/// This function configures the task to use for the data playback session. To prevent the possibility of errors, no other programs or commands should be executed on the specified task while a data playback session is occurring.
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \param[in] taskId The task to consume
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackSetConsumedTask(SFPlaybackHandle playbackHandle, TASKID taskId);

/// \brief Starts a data playback session with the specified configuration.
///
/// This function starts a data playback session with the specified configuration.
/// \param[in] handle The handle to the A3200
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStart(A3200Handle handle, SFPlaybackHandle playbackHandle);

/// \brief Retrieves status information about a currently executing data playback session.
///
/// This function retrieves status information about a currently executing data playback session.
/// \param[in] handle The handle to the A3200
/// \param[out] pStatus A pointer to a SFPlaybackStatus struct to be filled in with current data playback status information
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStatus(A3200Handle handle, SFPlaybackStatus* pStatus);

/// \brief Stops a currently executing data playback session.
///
/// This function stops a currently executing data playback session.
/// \param[in] handle The handle to the A3200
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackStop(A3200Handle handle, SFPlaybackHandle playbackHandle);

/// \brief Waits for completion of a currently executing data playback sesion.
///
/// This function waits for completion of a currently executing data playback sesion.
/// \param[in] handle The handle to the A3200
/// \param[in] playbackHandle The handle to a Sensor Fusion data playback configuration object
/// \return TRUE on success, FALSE if an error occurred. Call A3200GetLastError() for more information.
BOOL DLLENTRYDECLARATION A3200SFPlaybackWaitForCompletion(A3200Handle handle, SFPlaybackHandle playbackHandle);

/// @}

#ifdef __cplusplus
}
#endif

#endif __A3200_SFPLAYBACK__